<script>
import BaseAddForm from '../components/baseForm/add';
export default {
    props: {

    },
    extends: BaseAddForm,
    data () {
        return {}
    },
    mounted () {
        const { formName, parentName, parentOrgId, parentOrgName } = this;

        if (!(parentOrgId || parentOrgName)) {
            this.$x.toast.error('未找到父级单位');
            this.$router.back();
        }

        this.values = (function () {
            const values = {
                'OrgParty': {
                    belong_group_id: parentOrgName
                },
                'OrgPartyJS': {
                    belong_group_id: parentOrgName
                },
                'OrgUnit': {
                    parent_name: parentOrgName
                }
            };
            return values[formName];
        })();
    },
    methods: {
        submit: function () {
            const { formName, parentId, parentNodeId, parentOrgId } = this;
            this.$f.validate((valid) => {
                if (valid) {
                    const formData = this.formatSubmitData(formName, this.$f.formData());
                    this.$x.post('/orginfo/orgOperation/orgSave', {
                        parent_group_id: parentId,
                        belong_group_id: parentOrgId,
                        data: formData
                    }).then(() => {
                        this.$message.success('新增成功！');
                        this.$emit('listChanged')
                        this.$router.back();
                    });
                }
            });
        }
    }
}
</script>
